package com.xiaocz.hblsubstitutedriving.service;

import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.xiaocz.common.widgets.dialog.CustomDialog;
import com.xiaocz.hblsubstitutedriving.R;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Time:2019/10/24
 * Created by xiaocz
 * Describe
 */
public class BackstageService extends Service {

    private Context mContext;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        mContext = this;
        System.out.println("----------创建BackstageService");

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
            }
        }, 4000, 6000);
        super.onCreate();
    }

    /**
     * socket监听
     */
    private void socketListener() {}


    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg != null && msg.what == 1) {
                onDialogPurchase();
            }
            super.handleMessage(msg);
        }
    };

    /**
     * 司机状态
     */
    private void dialogWork() {
        AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
        builder.setTitle("请联系您的司管");
        builder.setCancelable(false);
        builder.setMessage("-----------------------------");
        builder.setNegativeButton("联系司管", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        builder.setPositiveButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        builder.create().show();
    }

    /**
     * 对话框
     */
    private void onDialogPurchase() {
        final CustomDialog.Builder builder = new CustomDialog.Builder(getApplicationContext());
        View layout = LayoutInflater.from(mContext).inflate(R.layout.dialog_list, null);
        builder.setContentView(layout);
        builder.setGravity(Gravity.BOTTOM);
        builder.setDialogWidthAndPX(WindowManager.LayoutParams.MATCH_PARENT);
        builder.setDialogHeightAndPX(WindowManager.LayoutParams.WRAP_CONTENT);
        final CustomDialog dialog = builder.create();
        dialog.show();
    }

    @Override
    public void onDestroy() {
        System.out.println("----------销毁BackstageService");
        super.onDestroy();
    }
}
